/*
 * @Copyright: Copyright (c) 2030 吴周海
 * @Author: wzh200x@126.com
 * @Date: 2025-10-09 16:07:21
 * @LastEditors: wzh200x@126.com
 * @LastEditTime: 2025-10-20 10:42:17
 * @FilePath: \gogamewebserver\goGameWebServer\internal\common\utils\timeHelper.go
 * @Description: 文件功能描述
 */
package utils

import (
	"time"

	"github.com/gogf/gf/v2/os/gtime"
)

func GetNowTimestampSecond() int64 {
	return time.Now().Unix()
}

func GetNowTimestampNanoSecond() int64 {
	return time.Now().UnixNano() / 1e6
}

func GetNowTimeFormat() string {
	return time.Now().Format("2006-01-02 15:04:05")
}

func GetTimestampSecond(timeStr string) int64 {
	gt := gtime.New(timeStr)
	return gt.Timestamp()
}

func GetTimeStrFromTimestamp(t int64) string {
	if t == 0 {
		return gtime.Now().Format("Y-m-d H:i:s")
	}
	gt := gtime.New(t)
	return gt.Format("Y-m-d H:i:s")
}

// GetSubDate 获取当前日期减去指定天数后的日期字符串
// days: 要减去的天数
// 返回格式: yyyy-mm-dd
func GetSubDate(days int) string {
	now := time.Now()
	subDate := now.AddDate(0, 0, -days)
	return subDate.Format("2006-01-02")
}
